package com.gitee.sdlszjb.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * 文件描述
 *
 * @author 庄壮壮
 * @since 2021-01-09 13:37
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AniviaResponse {
    private boolean success = false;
    private Object data;
    private int errorCode;
    private String errorMessage;
    private ErrorShowType showType;
    private String traceId;
    private String host;

    public enum ErrorShowType {
        //0 silent; 1 message.warn; 2 message.error; 4 notification; 9 page;
        SILENT(0),
        MESSAGE_WARN(1),
        MESSAGE_ERROR(2),
        NOTIFICATION(3),
        PAGE(4)
        ;
        private final int code;

        ErrorShowType(int code) {
            this.code = code;
        }

        @JsonValue
        public int getCode() {
            return code;
        }
    }

    public static AniviaResponse success(Object data) {
        AniviaResponse antdResponse = new AniviaResponse();
        antdResponse.success = true;
        antdResponse.errorCode = 0;
        antdResponse.data = data;
        return antdResponse;
    }

    public static AniviaResponse error(int code, String message) {
        AniviaResponse antdResponse = new AniviaResponse();
        antdResponse.success = false;
        antdResponse.errorCode = code;
        antdResponse.errorMessage = message;
        antdResponse.showType = ErrorShowType.MESSAGE_ERROR;
        return antdResponse;
    }

    public static AniviaResponse error(String message) {
        return error(400, message);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getTraceId() {
        return traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public ErrorShowType getShowType() {
        return showType;
    }

    public void setShowType(ErrorShowType showType) {
        this.showType = showType;
    }
}
